/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.myapp.struts.form;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

/**
 *
 * @author aacede
 */
public class LoginForm extends org.apache.struts.action.ActionForm {

    private String email;
    private String pass;
    private String pass2;
    private String nombre;
    private String apellidos;
    private int id;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPass() {
        return pass;
    }

    public void setPass(String pass) {
        this.pass = pass;
    }

    public String getPass2() {
        return pass2;
    }

    public void setPass2(String pass2) {
        this.pass2 = pass2;
    }

    public String getNombre() {
        return nombre;
    }

    public void setNombre(String nombre) {
        this.nombre = nombre;
    }

    public String getApellidos() {
        return apellidos;
    }

    public void setApellidos(String apellidos) {
        this.apellidos = apellidos;
    }

    @Override
    public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
        ActionErrors errors = new ActionErrors();
        if (getEmail() == null || getEmail().length() < 1) {
            errors.add("email", new ActionMessage("error.email.required"));
        }else if(!getEmail().matches("^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+.[a-zA-Z.]{2,5}$")){
            errors.add("email", new ActionMessage("error.email.incorrect"));
        }else if (getPass() == null || getPass().length() < 1) {
            errors.add("pass", new ActionMessage("error.pass.required"));
        }/*else if(this.getNombre()==null || this.getNombre().length() < 1){
            errors.add("nombre", new ActionMessage("error.nombre.required"));
        }else if(this.getApellidos()==null || this.getApellidos().length() < 1){
            errors.add("apellidos", new ActionMessage("error.apellidos.required"));
        }*/
        return errors;
    }
}
